import router from "./router";
import useConfigStore from "./stores/moudels/configStore";
import useUserStore from "./stores/moudels/userStore";
import pinia from "./stores";
// //引入插件
import nprogress from "nprogress";
//引入样式
import "nprogress/nprogress.css";
let configStore = useConfigStore(pinia);
let userStore = useUserStore(pinia);
const whiteList = ["/home/Detail","/home/Registration","/home/Notice","/home/Stop","/home/Search"];
//前置路由
router.beforeEach((to,form,next)=>{
    let token = userStore.token;
    nprogress.start();
    if(token){
        next();
    }else {
        if(whiteList.indexOf(to.path) !== -1){
            next();
        }else{
            next('/home')
            configStore.changeDiglog(true);
        }
    }
})

//后置路由守卫
router.afterEach((to, from) => {
    userStore.getUserInfo();
    //关闭进度条
    nprogress.done();
  });
